473,465 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamic Context Menus

Hi,

A project I am working on has a requirement for dynamic
menus. For the most part this works really well.

The menus I'm creating a based on files and directories,
so naturally the menu creation takes some time.

The approach I took was to override the OnSelect method
of the MenuItem class, which had code to populate the
child items.

This worked really well until I had to use the menu as a
context menu.. I found that the context menu does not
refresh properly below the first level menu..

The only way I can get this to work correctly is to use
reflection to call the private UpdateMenuItem method on
the MenuItem class.

Has anybody else had experiance with this??

Is the fact that the MenuItem does not refresh correctly
when in a context menu a bug???

Any feedback would be great..

Cheers
Jul 21 '05 #1
3 4730
I just took a look at that and it does appear to be a serious BUG.
A workaround, other than your own, is to set the forms ContextMenu property
to the context menu in question. Of course this is not the ideal situation
as your context menu will now popup from every control that does not have
it's own context menu.

As for that slow menu generation, are you adding the MenuItems to your
ContextMenu in a loop? If so, a faster way is to create a MenuItem Array and
set each member of the array to a new menuitem from within the loop. Then
outside the loop use AddRange to add all the menu items at once.

"Eddie de Bear" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
Hi,

A project I am working on has a requirement for dynamic
menus. For the most part this works really well.

The menus I'm creating a based on files and directories,
so naturally the menu creation takes some time.

The approach I took was to override the OnSelect method
of the MenuItem class, which had code to populate the
child items.

This worked really well until I had to use the menu as a
context menu.. I found that the context menu does not
refresh properly below the first level menu..

The only way I can get this to work correctly is to use
reflection to call the private UpdateMenuItem method on
the MenuItem class.

Has anybody else had experiance with this??

Is the fact that the MenuItem does not refresh correctly
when in a context menu a bug???

Any feedback would be great..

Cheers

Jul 21 '05 #2
The reason me menu creation is slow is because the menu
is based on existance of files in the OS as well as
security settings in the database... This retrieval takes
time.. Not the actual menuitem creation itself..

I was actually hoping some of the MS guys could possibly
take a look at this problem, becuase I have spent several
days on this, and have come to the conclusion that it is
a bug...

-----Original Message-----
I just took a look at that and it does appear to be a serious BUG.A workaround, other than your own, is to set the forms ContextMenu propertyto the context menu in question. Of course this is not the ideal situationas your context menu will now popup from every control that does not haveit's own context menu.

As for that slow menu generation, are you adding the MenuItems to yourContextMenu in a loop? If so, a faster way is to create a MenuItem Array andset each member of the array to a new menuitem from within the loop. Thenoutside the loop use AddRange to add all the menu items at once.
"Eddie de Bear" <an*******@discussions.microsoft.com> wrote in messagenews:07****************************@phx.gbl...
Hi,

A project I am working on has a requirement for dynamic
menus. For the most part this works really well.

The menus I'm creating a based on files and directories, so naturally the menu creation takes some time.

The approach I took was to override the OnSelect method
of the MenuItem class, which had code to populate the
child items.

This worked really well until I had to use the menu as a context menu.. I found that the context menu does not
refresh properly below the first level menu..

The only way I can get this to work correctly is to use
reflection to call the private UpdateMenuItem method on
the MenuItem class.

Has anybody else had experiance with this??

Is the fact that the MenuItem does not refresh correctly when in a context menu a bug???

Any feedback would be great..

Cheers

.

Jul 21 '05 #3
Well this was really bugging me and I just couldn't let it go.
After many unsuccessful overcomplicated attempts I finally came up with a
very simple solution.

Remove the MenuItem that you wish to add items to, add the items then re-add
the Menuitem to the ContextMenu.

VB.Net Example

Dim DynamicParentIndex As Integer = DynamicParent.Index
MyContextMenu.MenuItems.Remove(DynamicParent)
DynamicParent.MenuItems.Clear 'Optional
DynamicParent.MenuItems.AddRange(DynamicMenuItemsA rray)
MyContextMenu.MenuItems.Add(DynamicParentIndex, DynamicParent)
"Eddie de Bear" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
Hi,

A project I am working on has a requirement for dynamic
menus. For the most part this works really well.

The menus I'm creating a based on files and directories,
so naturally the menu creation takes some time.

The approach I took was to override the OnSelect method
of the MenuItem class, which had code to populate the
child items.

This worked really well until I had to use the menu as a
context menu.. I found that the context menu does not
refresh properly below the first level menu..

The only way I can get this to work correctly is to use
reflection to call the private UpdateMenuItem method on
the MenuItem class.

Has anybody else had experiance with this??

Is the fact that the MenuItem does not refresh correctly
when in a context menu a bug???

Any feedback would be great..

Cheers

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Patryk | last post by:
Hi I'm making a web application which is a copy of existing desktop application. I use telerik controlls for MS visual studio I have a little bit complicated situation beacuse I need context...
1
by: Doug Bell | last post by:
Hi, If I modify my Registry adding a new key HKEY_CLASSES_ROOT\*\shell\Use My App\command with a (Default) Value of C:\Program Files\Doug\DotNetApps\MyApp.exe "%1" then right clicking on files in...
4
by: ssg31415926 | last post by:
I've got a ListView which can show many different types of object. I need to display a ContextMenu whose MenuItems depend on the object type. I was planning to pre-create the ContextMenus when...
2
by: Dino M. Buljubasic | last post by:
I have several context menus added to my form. The form is displaying items in listviews connected to the context menus. When I click on an item in a list view, a popup context menu shows allowing...
3
by: Eddie de Bear | last post by:
Hi, A project I am working on has a requirement for dynamic menus. For the most part this works really well. The menus I'm creating a based on files and directories, so naturally the menu...
3
by: RahimAsif | last post by:
I am writing an application that requires the a portion of the main menu to be dynamic. The menu has file, panels, view files and help across the top. The view files sub menu needs to be...
2
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
4
by: Karl | last post by:
Hi all, I want to write an application that is launched from the context menu in Windows Explorer/Computer. That is to say, when I am browsing around my hard drive and get to any location I...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.